package com.xcity.pomelo.response;

import java.util.ArrayList;
import java.util.Comparator;
import java.util.List;

import com.xcity.db.entity.Player;
import com.xcity.game.battle.pve.template.ResStageTypeTemplate;

import naga.x.net.impl.pomelo.PomeloMessage;
import naga.x.net.impl.pomelo.protocol.Message;

@PomeloMessage(type = Message.Type.RESPONSE)
public class ResStageTypeListResponse extends Response{
	
	private List<ResStageTypeInfo> list;
	
	public static class ResStageTypeInfo{
		public int type;
		public int dayCount;//已打次数
		public int totalCount;//总次数
		public int[] itemIds;//展示物品ID
		public int leftSecond;//剩余时间
		public int levelLimit;//等级限制
		public int cost;
		public ResStageTypeInfo(int type, int dayCount, int totalCount, int[] itemIds, int leftSecond, int lvlLimit, int cost){
			this.type = type;
			this.dayCount = dayCount;
			this.totalCount = totalCount;
			this.itemIds = itemIds;
			this.leftSecond = leftSecond;
			this.levelLimit = lvlLimit;
			this.cost = cost;
		}
	}

	public ResStageTypeListResponse(int serial, Player player, List<ResStageTypeTemplate> templateList) {
		super(serial);
		list = new ArrayList<>();
		for(int i= 0; i < templateList.size(); i++){
			ResStageTypeTemplate template = templateList.get(i);
			int dayCount = player.getResStages().getDayCountByType(template.getId());
			int totalCount = template.getMaxCount();
			int leftSecond = player.getResStages().getTypeInfo().getLeftSecondByType(i);
			int levellimit = template.getLevelLimit();
			int cost = template.getCost();
			ResStageTypeInfo info = new ResStageTypeInfo(template.getId(), dayCount, totalCount, template.getShowItem(), leftSecond, levellimit, cost);
			list.add(info);
		}
		
		list.sort(new Comparator<ResStageTypeInfo>() {
			@Override
			public int compare(ResStageTypeInfo o1, ResStageTypeInfo o2) {
				return o1.levelLimit - o2.levelLimit;
			}
		});
	}

	public List<ResStageTypeInfo> getList() {
		return list;
	}

	public void setList(List<ResStageTypeInfo> list) {
		this.list = list;
	}

}
